package cn.com.dhc.danlu.widget.couponview;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.Layout;
import android.text.style.LeadingMarginSpan;

class NumberIndentSpan implements LeadingMarginSpan {
    private final int gapWidth;
    private final int leadWidth;
    private final int index;

    NumberIndentSpan (int leadGap, int gapWidth, int index) {
        this.leadWidth = leadGap;
        this.gapWidth = gapWidth;
        this.index = index;
    }

    @Override
    public int getLeadingMargin (boolean first) {
        return leadWidth + gapWidth;
    }

    @Override
    public void drawLeadingMargin (Canvas c, Paint p, int x, int dir, int top, int baseline, int bottom, CharSequence text, int start, int end, boolean first, Layout l) {
        Paint.Style orgStyle = p.getStyle ();
        p.setStyle (Paint.Style.FILL);
        float width;
        String tem;

        if (first) {
            width = p.measureText ("01.");
            tem = (index < 10 ? "  " : "") + index;
            c.drawText (tem + ".", (leadWidth + x - width / 2) * dir, bottom - p.descent (), p);
        }
        p.setStyle (orgStyle);
    }

} 